package com.turnengine.client.global.user.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Verify User Data Serializer.
 */
public class VerifyUserDataSerializer extends AbstractCommandDataSerializer<Boolean> implements IVerifyUserDataSerializer {

	/**
	 * Creates a new Verify User Data Serializer.
	 */
	public VerifyUserDataSerializer() {
		super(VerifyUser.COMMAND_ID);
	}

	@Override
	public Boolean readReturnValue(IDataReader reader) throws IOException {
		Boolean value = reader.readBooleanObject(true);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, Boolean value) throws IOException {
		writer.writeBooleanObject(value, true);
	}

	@Override
	public IExecutableCommand<Boolean> readRequest(IDataReader reader) throws IOException {

		// Read fields
		int id = reader.readInt();
		long code = reader.readLong();
		int address = reader.readInt();

		// Create object
		VerifyUser object = new VerifyUser();
		object.setId(id);
		object.setCode(code);
		object.setAddress(address);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<Boolean> argument) throws IOException {
		VerifyUser object = (VerifyUser) argument;

		// Get fields
		int id = object.getId();
		long code = object.getCode();
		int address = object.getAddress();

		// Write fields
		writer.writeInt(id);
		writer.writeLong(code);
		writer.writeInt(address);
	}

	@Override
	public IExecutableCommandResponse<Boolean> newResponse() {
		return new VerifyUserResponse();
	}
}
